<?php

namespace App\Admin\Controllers;

use App\Models\CommonBank;
use App\Models\CommonUserTag;
use App\Models\SecurityUser;
use App\Models\Service;
use App\Models\ServiceCategory;
use App\Models\User;
use Encore\Admin\Controllers\AdminController;
use Illuminate\Http\Request;

class ApiController extends AdminController
{
   public function userPage(Request $request){
       $q = $request->get('q');
       return User::where('name', 'like', "%$q%")->paginate(null, ['id', 'name as text']);
   }

   public function user(Request $request) {
       $q = $request->get('q');
       return User::where('nickname', 'like', "$q%")->get(['id','nickname as text']);
   }

   public function commonTag(Request $request) {
       $q = $request->get('q');
       return CommonUserTag::where('name', 'like', "%$q%")->paginate(null, ['id', 'name as text']);
   }

    public function securityUser(Request $request) {
        $q = $request->get('q');
        return SecurityUser::where('name', 'like', "%$q%")->paginate(null, ['id', 'name as text']);
    }

    public function banklist(Request $request) {
        $q = $request->get('q');
        return CommonBank::where('name', 'like', "%$q%")->paginate(null, ['id', 'name as text']);
    }

    public function serviceCategory(Request $request){
        $q = $request->get('q');
        return ServiceCategory::where('name', 'like', "%$q%")->paginate(null, ['id', 'name as text']);
    }

    public function serviceList(Request $request){
        $q = $request->get('q');
        return Service::where('name', 'like', "%$q%")->paginate(null, ['id', 'name as text']);
    }
}
